package test;
/**
 * DatabaseDriver.java
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * This is an example of how to access the c4 databases
 *
 * @author David Strickland
 */
public class DatabaseDriver {
	
	public static void main (String[] args) {
		Statement stmt = null;
		ResultSet rs = null;
		String token;
		String query;
		
		String table = "account_information";
		String nameColumn = "name";
		String primaryPhoneColumn = "account_number";
		
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			
		    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/corporate?" + 
		                                   "user=c4_user&password=p@ssw0rd");

			stmt = conn.createStatement();
			query = "SELECT "+ nameColumn + ", " + primaryPhoneColumn +" FROM " + table;

		    rs = stmt.executeQuery(query);
		    
		    while(rs.next()) {
		    	 token = rs.getString(nameColumn) + " : " + rs.getString(primaryPhoneColumn);
				 System.out.println(token);
		    }
		} catch (SQLException ex) {
		    // handle any errors
		    System.out.println("SQLException: " + ex.getMessage());
		    System.out.println("SQLState: " + ex.getSQLState());
		    System.out.println("VendorError: " + ex.getErrorCode());
		}
		catch (Exception e) {
			
		}
		finally {
		    if (rs != null) {
		        try {
		            rs.close();
		        } catch (SQLException sqlEx) { // ignore
		        rs = null;
		    }
		    if (stmt != null) {
		        try {
		            stmt.close();
		        } catch (SQLException sqlEx) { // ignore
		        stmt = null;
		    }
		}
	}
}
	}
}
